package com.jshop.msg.socket;

import com.jshop.api.annotation.IgnoreAuth;
import com.jshop.common.result.CommonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 **/
@Api(tags = "测试websocket")
@Controller
@RequestMapping("/checkcenter")
public class CheckCenterController {

    @Autowired
    private SocketServer socketService;



    //推送数据接口
    @ResponseBody
    @IgnoreAuth
    @Async
    @GetMapping("/socket/push")
    public CommonResult pushToWeb(Integer cid, String title, @RequestParam String message) throws InterruptedException, IOException {
        SocketServer.sendInfo(message,1);
        return CommonResult.successData("CASD");
    }

    //关闭WebSocket 连接
    @IgnoreAuth
    @GetMapping("/socket/close")
    public CommonResult close(@RequestParam Integer userId) {
        socketService.onClose(userId);
        return CommonResult.successData("成功关闭");
    }

}
